<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找重复，把一个数组(arr1)里重复的数放到另一个数组(arr2)里，并打印 arr2。</title>
</head>

<body>
  <script>
    // var arr1 = [12, 32, 43, 14, 52, 12, 52, 36, 52]
    // var arr2 = [];
    // for (let i = 0; i < arr1.length; i++) {
    //   for (let j = i + 1; j < arr1.length; j++) {
    //     if (arr1[i] === arr1[j] && arr2.indexOf(arr1[j]) === -1) {
    //       arr2.push(arr1[i]);
    //     }
    //   }
    // }
    // console.log(arr1);
    // console.log(arr2);



    var arr1 = [12, 32, 43, 14, 52, 12, 52, 36, 52]
    var arr2 = []
    for (let i = 0; i < arr1.length; i++) {
      for (let j = i + 1; j < arr1.length; j++) {
        if (arr1[i] === arr1[j] && arr2.indexOf(arr1[j]) === -1) {
          arr2.push(arr1[i])
        }
      }
    }
    console.log(arr1);
    console.log(arr2);

  </script>
</body>

</html>